package com.logichina.lpromis.tjgy.sf;

import java.util.Set;

import com.logi.lpromis.log.LogisLog;
import com.logichina.lpromis.tjgy.ftp.FTPService;

public class SFDownloadZip
{
	public static void main(String[] args)
	{
		while(true)
		{
			try
			{
				SFDownloadZip.doAction();
				Thread.sleep(5000);
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
		}
	}
	
	public static void doAction() throws Exception
	{
		Set<String> fileList = FTPService.getFileList(SFUtil.FTP_DOWNLOAD_DIR);
		for (String zipName : fileList)
		{
			if(zipName.toUpperCase().endsWith(".ZIP"))
			{
				try
				{
					// 从FTP下载ZIP文件内容
					byte[] zipByte = FTPService.downloadFile(SFUtil.FTP_DOWNLOAD_DIR, zipName);
					// 将ZIP存入DOWNLOAD文件夹
					SFUtil.saveZipToDir(SFUtil.DOWNLOAD_DIR, zipName, zipByte);
					// 删除原有文件
					FTPService.deleteFile(SFUtil.FTP_DOWNLOAD_DIR, zipName);
				}
				catch (Exception e)
				{
					LogisLog.error(e, "下载ZIP文件(" + zipName + ")时出错:");
				}
			}
		}
	}
}
